home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / BCHGCL.C < prev    next >
C/C++ Source or Header  |  1992-05-04  |  8KB  |  305 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/bchgcl.c,v 9.44 1992/05/04 18:31:41 jinx Exp $
  4.  
  5. Copyright (c) 1987-1992 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* bchgcl, bchmmg, bchpur, and bchdmp can replace gcloop, memmag,
  36.    purify, and fasdump, respectively, to provide garbage collection
  37.    and related utilities to disk. */
  38.  
  39. #include "scheme.h"
  40. #include "bchgcc.h"
  41.  
  42. SCHEME_OBJECT *
  43. DEFUN (GCLoop, (Scan, To_ptr, To_Address_ptr),
  44.        fast SCHEME_OBJECT *Scan AND
  45.        SCHEME_OBJECT **To_ptr AND
  46.        SCHEME_OBJECT **To_Address_ptr)
  47. {
  48.   fast SCHEME_OBJECT *To, *Old, Temp, *Low_Constant, *To_Address, New_Address;
  49.  
  50.   To = *To_ptr;
  51.   To_Address = *To_Address_ptr;
  52.   Low_Constant = Constant_Space;
  53.  
  54.   for ( ; Scan != To; Scan++)
  55.   {
  56.     Temp = *Scan;
  57.     Switch_by_GC_Type (Temp)
  58.     {
  59.       case TC_BROKEN_HEART:
  60.         if (Temp != (MAKE_POINTER_OBJECT (TC_BROKEN_HEART, Scan)))
  61.     {
  62.       sprintf (gc_death_message_buffer,
  63.            "gcloop: broken heart (0x%lx) in scan",
  64.            Temp);
  65.       gc_death (TERM_BROKEN_HEART, gc_death_message_buffer, Scan, To);
  66.       /*NOTREACHED*/
  67.     }
  68.     if (Scan != scan_buffer_top)
  69.       goto end_gcloop;
  70.     /* The -1 is here because of the Scan++ in the for header. */
  71.     Scan = ((dump_and_reload_scan_buffer (0, NULL)) - 1);
  72.     continue;
  73.  
  74.       case TC_MANIFEST_NM_VECTOR:
  75.       case TC_MANIFEST_SPECIAL_NM_VECTOR:
  76.     /* Check whether this bumps over current buffer,
  77.        and if so we need a new bufferfull. */
  78.     Scan += (OBJECT_DATUM (Temp));
  79.     if (Scan < scan_buffer_top)
  80.     {
  81.       break;
  82.     }
  83.     else
  84.     {
  85.       unsigned long overflow;
  86.  
  87.       /* The + & -1 are here because of the Scan++ in the for header. */
  88.       overflow = ((Scan - scan_buffer_top) + 1);
  89.       Scan = ((dump_and_reload_scan_buffer
  90.            ((overflow >> gc_buffer_shift), NULL)
  91.            + (overflow & gc_buffer_mask)) - 1);
  92.       break;
  93.     }
  94.  
  95.       case_compiled_entry_point:
  96.     relocate_compiled_entry (true);
  97.     *Scan = Temp;
  98.     break;
  99.  
  100.       case TC_LINKAGE_SECTION:
  101.       {
  102.     switch (READ_LINKAGE_KIND (Temp))
  103.     {
  104.       case REFERENCE_LINKAGE_KIND:
  105.       case ASSIGNMENT_LINKAGE_KIND:
  106.       {
  107.         /* count typeless pointers to quads follow. */
  108.  
  109.         fast long count;
  110.         long max_count, max_here;
  111.  
  112.         Scan++;
  113.         max_here = (scan_buffer_top - Scan);
  114.         max_count = (READ_CACHE_LINKAGE_COUNT (Temp));
  115.         while (max_count != 0)
  116.         {
  117.           count = ((max_count > max_here) ? max_here : max_count);
  118.           max_count -= count;
  119.           for ( ; --count >= 0; Scan += 1)
  120.           {
  121.         Temp = *Scan;
  122.         relocate_typeless_pointer (copy_quadruple (), 4);
  123.           }
  124.           if (max_count != 0)
  125.           {
  126.         /* We stopped because we needed to relocate too many. */
  127.         Scan = (dump_and_reload_scan_buffer (0, NULL));
  128.         max_here = gc_buffer_size;
  129.           }
  130.         }
  131.         /* The + & -1 are here because of the Scan++ in the for header. */
  132.         Scan -= 1;
  133.         break;
  134.       }
  135.  
  136.       case OPERATOR_LINKAGE_KIND:
  137.       case GLOBAL_OPERATOR_LINKAGE_KIND:
  138.       {
  139.         /* Operator linkage */
  140.  
  141.         fast long count;
  142.         fast char * word_ptr, * next_ptr;
  143.         long overflow;
  144.  
  145.         word_ptr = (FIRST_OPERATOR_LINKAGE_ENTRY (Scan));
  146.         if (word_ptr > ((char *) scan_buffer_top))
  147.         {
  148.           overflow = (word_ptr - ((char *) Scan));
  149.           extend_scan_buffer (word_ptr, To);
  150.           BCH_START_OPERATOR_RELOCATION (Scan);
  151.           word_ptr = (end_scan_buffer_extension (word_ptr));
  152.           Scan = ((SCHEME_OBJECT *) (word_ptr - overflow));
  153.         }
  154.         else
  155.           BCH_START_OPERATOR_RELOCATION (Scan);
  156.         
  157.         count = (READ_OPERATOR_LINKAGE_COUNT (Temp));
  158.         overflow = ((END_OPERATOR_LINKAGE_AREA (Scan, count)) -
  159.             scan_buffer_top);
  160.  
  161.         for (next_ptr = (NEXT_LINKAGE_OPERATOR_ENTRY (word_ptr));
  162.          (--count >= 0);
  163.          word_ptr = next_ptr,
  164.          next_ptr = (NEXT_LINKAGE_OPERATOR_ENTRY (word_ptr)))
  165.         {
  166.           if (next_ptr > ((char *) scan_buffer_top))
  167.           {
  168.         extend_scan_buffer (next_ptr, To);
  169.         relocate_linked_operator (true);
  170.         next_ptr = (end_scan_buffer_extension (next_ptr));
  171.         overflow -= gc_buffer_size;
  172.           }
  173.           else
  174.         relocate_linked_operator (true);
  175.         }
  176.         Scan = (scan_buffer_top + overflow);
  177.         BCH_END_OPERATOR_RELOCATION (Scan);
  178.         break;
  179.       }
  180.  
  181.       default:
  182.       {
  183.         gc_death (TERM_EXIT,
  184.               "GC: Unknown compiler linkage kind.",
  185.               Scan, Free);
  186.         /*NOTREACHED*/
  187.       }
  188.     }
  189.     break;
  190.       }
  191.  
  192.       case TC_MANIFEST_CLOSURE:
  193.       {
  194.     fast long count;
  195.     fast char * word_ptr;
  196.     char * end_ptr;
  197.  
  198.     Scan += 1;
  199.  
  200.     /* Is there enough space to read the count? */
  201.  
  202.     end_ptr = (((char *) Scan) + (2 * (sizeof (format_word))));
  203.     if (end_ptr > ((char *) scan_buffer_top))
  204.     {
  205.       long dw;
  206.  
  207.       extend_scan_buffer (end_ptr, To);
  208.       BCH_START_CLOSURE_RELOCATION (Scan - 1);
  209.       count = (MANIFEST_CLOSURE_COUNT (Scan));
  210.       word_ptr = (FIRST_MANIFEST_CLOSURE_ENTRY (Scan));
  211.       dw = (word_ptr - end_ptr);
  212.       end_ptr = (end_scan_buffer_extension (end_ptr));
  213.       word_ptr = (end_ptr + dw);
  214.       Scan = ((SCHEME_OBJECT *) (end_ptr - (2 * (sizeof (format_word)))));
  215.     }
  216.     else
  217.     {
  218.       BCH_START_CLOSURE_RELOCATION (Scan - 1);
  219.       count = (MANIFEST_CLOSURE_COUNT (Scan));
  220.       word_ptr = (FIRST_MANIFEST_CLOSURE_ENTRY (Scan));
  221.     }
  222.     end_ptr = ((char *) (MANIFEST_CLOSURE_END (Scan, count)));
  223.  
  224.     for ( ; ((--count) >= 0);
  225.          (word_ptr = (NEXT_MANIFEST_CLOSURE_ENTRY (word_ptr))))
  226.     {
  227.       if ((CLOSURE_ENTRY_END (word_ptr)) > ((char *) scan_buffer_top))
  228.       {
  229.         char * entry_end;
  230.         long de, dw;
  231.  
  232.         entry_end = (CLOSURE_ENTRY_END (word_ptr));
  233.         de = (end_ptr - entry_end);
  234.         dw = (entry_end - word_ptr);
  235.         extend_scan_buffer (entry_end, To);
  236.         relocate_manifest_closure (true);
  237.         entry_end = (end_scan_buffer_extension (entry_end));
  238.         word_ptr = (entry_end - dw);
  239.         end_ptr = (entry_end + de);
  240.       }
  241.       else
  242.         relocate_manifest_closure (true);
  243.     }
  244.     Scan = ((SCHEME_OBJECT *) (end_ptr));
  245.     BCH_END_CLOSURE_RELOCATION (Scan);
  246.     break;
  247.       }
  248.  
  249.       case_Cell:
  250.     relocate_normal_pointer (copy_cell(), 1);
  251.  
  252.       case TC_REFERENCE_TRAP:
  253.     if ((OBJECT_DATUM (Temp)) <= TRAP_MAX_IMMEDIATE)
  254.     {
  255.       /* It is a non pointer. */
  256.       break;
  257.     }
  258.     /* It is a pair, fall through. */
  259.       case_Pair:
  260.     relocate_normal_pointer (copy_pair (), 2);
  261.  
  262.       case TC_VARIABLE:
  263.       case_Triple:
  264.     relocate_normal_pointer (copy_triple (), 3);
  265.  
  266.       case_Quadruple:
  267.     relocate_normal_pointer (copy_quadruple (), 4);
  268.  
  269.       case TC_BIG_FLONUM:
  270.     relocate_flonum_setup ();
  271.     goto Move_Vector;
  272.  
  273.       case_Vector:
  274.     relocate_normal_setup ();
  275.       Move_Vector:
  276.     copy_vector (NULL);
  277.     relocate_normal_end ();
  278.  
  279.       case TC_FUTURE:
  280.     relocate_normal_setup ();
  281.     if (!(Future_Spliceable (Temp)))
  282.     {
  283.       goto Move_Vector;
  284.     }
  285.     *Scan = (Future_Value (Temp));
  286.     Scan -= 1;
  287.     continue;
  288.  
  289.       case TC_WEAK_CONS:
  290.     relocate_normal_pointer (copy_weak_pair (), 2);
  291.  
  292.       default:
  293.     GC_BAD_TYPE ("gcloop");
  294.     /* Fall Through */
  295.  
  296.       case_Non_Pointer:
  297.     break;
  298.       }
  299.   }
  300. end_gcloop:
  301.   *To_ptr = To;
  302.   *To_Address_ptr = To_Address;
  303.   return (Scan);
  304. }
  305.